package com.msg.test.model;

import com.msg.test.util.MsgUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

/**
 * Created by Administrator on 2017/10/19 0019.
 */
public class MsgConnect extends MsgHead{
    private static Log log = LogFactory.getLog(MsgConnect.class);
    private String sourceAddr; //源地址
    private byte[] AuthenticatorSource;//用于鉴别源地址
    private byte version; //双方协商的版本号
    private int timestamp;//时间戳明文

    public byte[] toByteArray(){
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(bos);
        try{
            dos.writeInt(this.getTotalLength());
            dos.writeInt(this.getCommandId());
            dos.writeInt(this.getSequence());
            MsgUtil.writeString(dos,this.sourceAddr,6);
            dos.write(getAuthenticatorSource());
            dos.writeByte(version);
            dos.writeInt(timestamp);
            dos.close();
        }catch (Exception ex){
            log.error("");
        }
        return bos.toByteArray();
    }
    public String getSourceAddr() {
        return sourceAddr;
    }

    public void setSourceAddr(String sourceAddr) {
        this.sourceAddr = sourceAddr;
    }

    public byte[] getAuthenticatorSource() {
        return AuthenticatorSource;
    }

    public void setAuthenticatorSource(byte[] authenticatorSource) {
        AuthenticatorSource = authenticatorSource;
    }

    public byte getVersion() {
        return version;
    }

    public void setVersion(byte version) {
        this.version = version;
    }

    public int getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(int timestamp) {
        this.timestamp = timestamp;
    }
}
